package com.example.lib_router

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.example.lib_base.conts.BaseConst
import com.example.lib_base.path.RouterPath
import com.tencent.mmkv.MMKV

/**
 *  页面路由参数拦截器
 *
 *  场景:页面追踪
 */

@Interceptor(priority = 4, name = "路由参数拦截器")
class RouterParamsInterceptor :IInterceptor {
    protected lateinit var mContext: Context
    override fun init(context: Context?) {
        context?.let { 
            mContext=it
        }
    }

    override fun process(postcard: Postcard?, callback: InterceptorCallback?) {
        //获取Token
        val traceId = MMKV.defaultMMKV().decodeString("traceId", BaseConst.APP_ACCESS_ID)
        if (traceId.isNullOrEmpty()) {
            postcard?.withString("traceId",traceId)
        }
        callback?.onContinue(postcard)
    }
}